package com.ymatou.iapi.settlement.testcase;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFeeTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFreightTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.AgreeRefundReq;
import com.ymatou.iapi.optrade.parameter.req.ApplyRefundReq;
import com.ymatou.iapi.optrade.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymatou.iapi.optrade.parameter.vo.OrderGroupVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderVo;
import com.ymatou.iapi.optrade.parameter.vo.SalesRefundInfoVo;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.AgreeRefundCall;
import com.ymatou.iapi.optrade.service.RefundService;
import com.ymatou.iapi.settlement.parameter.GenerateAnliSettlementReq;
import com.ymatou.iapi.settlement.parameter.OrderSettlementReq;
import com.ymatou.iapi.settlement.service.GenerateAnliSettlementCall;
import com.ymatou.iapi.settlement.service.GenerateInvoicesOnOrderReceivedCall;
import com.ymatou.iapi.settlement.service.SettlementService;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AnlihuiCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAnliOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAuthenticateCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingProductVo;
import com.ymttest.database.model.YmtAnliSettlementDetail;
import com.ymttest.database.model.YmtCommissionDetail;
import com.ymttest.database.model.YmtSettlementInvoice;
import com.ymttest.database.sharding.db.ext.model.OrderExtPo;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sharding.db.sqlwapper.OrderWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtAnliSettlementDetailWrapper;
import com.ymttest.database.sqlwapper.YmtCommissionDetailWapper;
import com.ymttest.database.sqlwapper.YmtSettlementInvoiceWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 确认收货生成确认收货,佣金结算单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GenerateInvoicesOnOrderReceived {

	private static OrderSettlementReq orderSettlementReq;
	private static GenerateInvoicesOnOrderReceivedCall generateinvoicesCall;

	private static OrderShardingWapper defaultWapper = new OrderShardingWapper();

	private static GenerateAnliSettlementReq generateAnliSettlementReq = new GenerateAnliSettlementReq();
	private static GenerateAnliSettlementCall generateAnliSettlementCall = new GenerateAnliSettlementCall();

	private static AgreeRefundReq salesrefundsuccessReq = new AgreeRefundReq();
	private static AgreeRefundCall salesrefundsuccessCall = new AgreeRefundCall();

	private static Long sellerId = Long.valueOf(EnvSetup
			.getData("autotest_seller1"));
	private static String sellerName = String.valueOf(EnvSetup
			.getData("autotest_sellerName1"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("确认收货时生成结算单接口");
	}

	@Before
	public void caseUp() {
		orderSettlementReq = new OrderSettlementReq();
		generateinvoicesCall = new GenerateInvoicesOnOrderReceivedCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(generateinvoicesCall.getOpurl());

		defaultWapper.activeDeadCommunicationsLink(defaultWapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 返佣规则:
	 * 
	 * 1.新买手（审核通过之日的时间在60天以内）,新客,老客全部返佣金（先收,后返） add 2018.3.1 新买手新客不返了 2.老买手,老客
	 * 返还佣金 add 2018.5.1 开始老客不返.老客订单单件商品收取佣金上限单独设置。（50元） 3.老买手,新用户 不返还佣金
	 * 
	 * add 2018.6.1 开始都不返佣金。 返佣比例为0 ,生成的返佣结算单 金额为0
	 * 
	 */

	private void verifyDb() {

		long orderId = orderSettlementReq.getOrderId();
		// long orderId = 9118038699L;
		try {

			Thread.sleep(3000);

			OrderCallService orderCallService = new OrderCallService();

			// 订单主表
			OrderPo orderPo = defaultWapper.selectOrderbyOrderId(orderId);

			Boolean isCanceled = TradingCallService.isCanceledOrder(orderPo);

			int sellerId = orderPo.getSellerId().intValue();

			// 下单使用的返点金额
			BigDecimal rebateAmount = orderPo.getRebatePaidAmount();

			// 佣金
			List<YmtCommissionDetail> ymtCommissionDetailList = new YmtCommissionDetailWapper()
					.selectByOrderId(orderId);

			// 结算佣金
			List<YmtCommissionDetail> ymtSettlemCommissionDetailList = ymtCommissionDetailList
					.stream()
					.filter(commission -> commission.getInvoiceType() == 4)
					.collect(Collectors.toList());

			// 返还佣金
			/*
			 * List<YmtCommissionDetail> ymtBackCommissionDetailList =
			 * ymtCommissionDetailList .stream() .filter(commission ->
			 * commission.getInvoiceType() == 6) .collect(Collectors.toList());
			 */

			// // 订单退款平台券
			// BigDecimal productRefundSettlementAmountOfCoupon =
			// BigDecimal.ZERO;

			// 订单总的退运费
			BigDecimal orderRefundedAmountOfFreight = BigDecimal.ZERO;

			// 结算佣金
			for (YmtCommissionDetail ymtCommissionDetail : ymtSettlemCommissionDetailList) {

				Logger.comment("校验Ymt_CommissionDetail表");

				Logger.comment("校验商品id:" + ymtCommissionDetail.getProductId());
				;

				String catalogId = ymtCommissionDetail.getProductId();

				// 订单商品表
				OrderDetailPo ymtOrderInfo = defaultWapper
						.selectOrderDetailbyOrderIdAndCatalogId(orderId,
								catalogId);
				// 商品实际购买数量
				int iAmount = (Integer) ymtOrderInfo.getProductCount();

				// Ymt_CommissionDetail表商品实际付款金额无需计算返点金额
				BigDecimal proRealPayAmount = SettlementService
						.getOrderDetailPaidAmount(ymtOrderInfo);

				// 退款信息表
				RefundBillPo refundBillPo = defaultWapper
						.selectRefundBillByOrderIdAndCatalogId(orderId,
								catalogId);

				// 商品结算佣金数量
				int productCommissAmount = iAmount;
				// 商品结算佣金金额
				BigDecimal productRealPayAmount = proRealPayAmount
						.add(ymtOrderInfo.getYmtCouponAmount());

				if (refundBillPo != null) {

					// 商品使用的平台优惠券金额
					BigDecimal productCouponAmount = Utils
							.zeroIfNull(ymtOrderInfo.getYmtCouponAmount());

					// 商品退款金额
					BigDecimal productRefundSettlementAmount = refundBillPo
							.getTotalAmount().subtract(productCouponAmount);
					// 商品退款平台券
					// productRefundSettlementAmountOfCoupon =
					// refundBillPo.getDeductedCouponAmount();

					// productRefundSettlementAmountOfCoupon =
					// refundBillPo.getNoSettlementCouponAmount();

					// 商品申请退款的运费
					BigDecimal productRefundedAmountOfFreight = refundBillPo
							.getFreight();

					orderRefundedAmountOfFreight = orderRefundedAmountOfFreight
							.add(productRefundedAmountOfFreight);

					// 商品退款数量
					int productRefundProductNum = refundBillPo
							.getProductCount();

					// 计算商品实际算拥的支付金额 实际支付-退款
					productRealPayAmount = proRealPayAmount.subtract(
							productRefundSettlementAmount).compareTo(
							BigDecimal.ZERO) < 1 ? BigDecimal.ZERO
							: proRealPayAmount
									.subtract(productRefundSettlementAmount);

					// 商品计算佣金数量, 实际支付数量-退款数量
					productCommissAmount = (iAmount - productRefundProductNum) < 0 ? 0
							: (iAmount - productRefundProductNum);

					// add 0616
					if ((productCommissAmount == 0)
							&& (productRealPayAmount.compareTo(BigDecimal.ZERO) > 0)) {

						productCommissAmount = 1;
					}
				}

				BigDecimal singleProRealPay;

				// 单个商品实际算佣金额
				if (productCommissAmount == 0) {

					singleProRealPay = BigDecimal.ZERO.setScale(2);

				} else {
					singleProRealPay = productRealPayAmount.divide(
							new BigDecimal(productCommissAmount), 2,
							RoundingMode.HALF_UP);
				}

				// 结算佣金商品的数量
				Logger.verifyEquals(productCommissAmount,
						ymtCommissionDetail.getProdNumOfCommission(),
						"验证ProdNumOfCommission");

				// 结算佣金单价的计算价格
				Logger.verifyEquals(singleProRealPay,
						ymtCommissionDetail.getRealPayAmountPerProd(),
						"验证RealPayAmountPerProd");

				// 单件商品佣金费率
				// 设置的单件商品最多佣金收费
				BigDecimal singleCommissionMax = ymtCommissionDetail
						.getSingleCommissionMax();
				// 设置的单件商品最少佣金收费
				BigDecimal singleCommissionMin = ymtCommissionDetail
						.getSingleCommissionMin();

				// 按比例计算出实际佣金收费
				BigDecimal singleCommission = ymtCommissionDetail
						.getRealPayAmountPerProd()
						.multiply(ymtCommissionDetail.getSingleCommissionRate())
						.divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP);

				if (singleCommission.compareTo(BigDecimal.ZERO) > 0) {

					/*
					 * 金额1=每件商品实际支付金额×商品佣金比例 金额2=max（金额1,单件商品收佣下限金额）
					 * 每件商品交易佣金=min（金额2,单件商品收佣上限金额）
					 */

					if (singleCommissionMin.compareTo(BigDecimal.ZERO) > 0) {
						singleCommission = singleCommissionMin;
					}

					if (singleCommissionMax.compareTo(BigDecimal.ZERO) > 0) {
						if (singleCommission.compareTo(singleCommissionMax) > 0)
							singleCommission = singleCommissionMax;
					}
				}

				Logger.verifyEquals(singleCommission,
						ymtCommissionDetail.getCommissionPerProd(),
						"验证CommissionPerProd");

				// 单件商品佣金费率*结算数量
				DataUtil.verifyDecimalEquals(
						ymtCommissionDetail.getCommissionPerProd().multiply(
								new BigDecimal(productCommissAmount)),
						ymtCommissionDetail.getCommissionAmount(),
						"验证CommissionAmount");
			}

			// 计算订单下所有商品佣金总和
			BigDecimal orderCommissionAmount = ymtSettlemCommissionDetailList
					.stream().map(m -> m.getCommissionAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			// 计算订单下所有运费总和
			BigDecimal orderRealPayFreight = ymtSettlemCommissionDetailList
					.stream().map(m -> m.getRealPayFreight())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			BigDecimal orderSellerRebateAmount = BigDecimal.ZERO;

			if (defaultWapper.isIncludeRebateProduct(orderId)) {

				// 计算订单下所有买手返点总和
				List<YmtAnliSettlementDetail> ymtAnliSettlementDetailList = new YmtAnliSettlementDetailWrapper()
						.selectByOrderId(orderId);

				orderSellerRebateAmount = ymtAnliSettlementDetailList.stream()
						.map(m -> m.getRebateAmount())
						.reduce(BigDecimal.ZERO, BigDecimal::add)
						.setScale(2, RoundingMode.HALF_UP);
			}

			// 查询交易退款结算表
			List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
					.selectYmtSettlementInvoice(String.valueOf(orderId));
			// 查询用户下单结算的金额
			BigDecimal settlementAmout = orderCallService
					.getReceiveAmountOfCash(orderId);
			// // 订单使用平台券金额
			// BigDecimal ymtCouponAmount = orderPo.getYmtPromotionAmount();
			// 订单总运费金额
			BigDecimal orderfFreight = orderPo.getFreight();

			// 如果没有InvoiceType = 14的结算单，则找InvoiceType = 4结算单

			if (ymtSettlemCommissionDetailList.size() == 0) {

				List<YmtCommissionDetail> ymtSettlemCommissionDetailList1 = ymtCommissionDetailList
						.stream()
						.filter(commission -> commission.getInvoiceType() == 14)
						.collect(Collectors.toList());

				BigDecimal orderRealPayFreight1 = ymtSettlemCommissionDetailList1
						.stream().map(m -> m.getRealPayFreight())
						.reduce(BigDecimal.ZERO, BigDecimal::add);

				DataUtil.verifyDecimalEquals(
						orderfFreight.subtract(orderRefundedAmountOfFreight),
						orderRealPayFreight1, "验证结算佣金表实际结算的运费金额");

			} else {
				DataUtil.verifyDecimalEquals(
						orderfFreight.subtract(orderRefundedAmountOfFreight),
						orderRealPayFreight, "验证结算佣金表实际结算的运费金额");
			}

			Logger.verifyEquals(true, settlementInvoiceList.size() >= 2,
					"验证结算表数据");

			for (YmtSettlementInvoice settlement : settlementInvoiceList) {
				// 确认收货收单
				if ((Integer) settlement.getBusinessType() == 1) {
					Logger.comment("校验Ymt_SettlementInvoice表,BusinessType == 1,下单确认收货结算");
					Logger.verifyEquals(String.valueOf(orderId),
							(String) settlement.getBusinessNo(), "验证BusinessNo");
					Logger.verifyEquals(1,
							(Integer) settlement.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId, settlement.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(
							((BigDecimal) settlement.getCashAmount()).add(
									(BigDecimal) settlement.getCouponAmount())
									.add(settlement.getRebatePaidAmount()),
							(BigDecimal) settlement.getTotalAmount(),
							"验证TotalAmount");
					Logger.verifyEquals(settlementAmout,
							(BigDecimal) settlement.getCashAmount(),
							"验证CashAmount");
					Logger.verifyEquals(
							settlement.getTotalAmount()
									.subtract(settlement.getCashAmount())
									.subtract(settlement.getRebatePaidAmount()),
							(BigDecimal) settlement.getCouponAmount(),
							"验证CouponAmount");
					Logger.verifyEquals(sellerId,
							(Integer) settlement.getSellerId(), "验证SellerId");
					Logger.verifyEquals("确认收货订单结算",
							(String) settlement.getRemark(), "验证Remark");
					Logger.verifyEquals(0,
							(Integer) settlement.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(2,
							(Integer) settlement.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							(String) settlement.getProcessResult(),
							"验证ProcessResult");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfAccountAmount(),
							"验证fAccountAmount");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfThirdPartyAmount(),
							"验证fThirdPartyAmount");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfThirdPartyAmount(),
							"验证fThirdPartyAmount");
					Logger.verifyEquals(Utils.zeroIfNull(rebateAmount),
							(BigDecimal) settlement.getRebatePaidAmount(),
							"验证rebatePaidAmount");
				}
				// 佣金结算
				if ((Integer) settlement.getBusinessType() == 4) {
					Logger.comment("校验Ymt_SettlementInvoice表,BusinessType == 4, 下单确认收货佣金结算");
					Logger.verifyEquals(String.valueOf(orderId),
							(String) settlement.getBusinessNo(), "验证BusinessNo");
					Logger.verifyEquals(4,
							(Integer) settlement.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId, settlement.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(((BigDecimal) settlement
							.getCashAmount()).add((BigDecimal) settlement
							.getCouponAmount()), (BigDecimal) settlement
							.getTotalAmount(), "验证TotalAmount");
					Logger.verifyEquals(orderCommissionAmount,
							(BigDecimal) settlement.getCashAmount(),
							"验证CashAmount");
					// 退的ymt 平台优惠券
					Logger.verifyEquals(BigDecimal.ZERO.setScale(2),
							(BigDecimal) settlement.getCouponAmount(),
							"验证CouponAmount");
					Logger.verifyEquals(sellerId,
							(Integer) settlement.getSellerId(), "验证SellerId");
					Logger.verifyEquals("收取交易服务费结算",
							(String) settlement.getRemark(), "验证Remark");
					Logger.verifyEquals(0,
							(Integer) settlement.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(2,
							(Integer) settlement.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							(String) settlement.getProcessResult(),
							"验证ProcessResult");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfAccountAmount(),
							"验证fAccountAmount");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfThirdPartyAmount(),
							"验证fThirdPartyAmount");
				}
				// 买手安利返点费用结算
				if ((Integer) settlement.getBusinessType() == 17) {
					Logger.comment("校验Ymt_SettlementInvoice表, BusinessType == 17, 买手安利返点费用结算");
					Logger.verifyEquals(String.valueOf(orderId),
							(String) settlement.getBusinessNo(), "验证BusinessNo");
					Logger.verifyEquals(17,
							(Integer) settlement.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId, settlement.getOrderId(),
							"验证OrderId");
					DataUtil.verifyDecimalEquals(orderSellerRebateAmount,
							settlement.getTotalAmount(), "验证TotalAmount");
					Logger.verifyEquals(orderSellerRebateAmount,
							(BigDecimal) settlement.getCashAmount(),
							"验证CashAmount");
					// 退的ymt 平台优惠券
					Logger.verifyEquals(BigDecimal.ZERO.setScale(2),
							(BigDecimal) settlement.getCouponAmount(),
							"验证CouponAmount");
					Logger.verifyEquals(sellerId,
							(Integer) settlement.getSellerId(), "验证SellerId");
					Logger.verifyEquals("买手安利返点费用",
							(String) settlement.getRemark(), "验证Remark");
					Logger.verifyEquals(isCanceled ? 3 : 0,
							(Integer) settlement.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(2,
							(Integer) settlement.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							(String) settlement.getProcessResult(),
							"验证ProcessResult");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfAccountAmount(),
							"验证fAccountAmount");
					Logger.verifyEquals(null,
							(BigDecimal) settlement.getfThirdPartyAmount(),
							"验证fThirdPartyAmount");
				}
			}
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_001() {
		Logger.start(true, "使用平台券,商家券。确认收货,校验生成下单结算单,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			// 创建一个拼邮的订单
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLogisticsType(LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			long userId = placeOrderResp.getUserId();
			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);
			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);

			// 不用主动调用,走消息总线
			/*
			 * ;
			 * 
			 * Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
			 * "验证返回报文");
			 */

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_003() {
		Logger.start(true, "订单里一个商品全款退款,确认收货后,校验生成订单结算单佣金结算单");
		try {
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);
			/*
			 * ;
			 * 
			 * Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
			 * "验证返回报文");
			 */

			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_004() {
		Logger.start(true, "订单里一个商品部分退款,确认收货后,校验生成订单结算单佣金结算单");

		try {
			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(2000);

			// 第一个商品全款退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order, 1);

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;

			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(2000);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_005() {
		Logger.start(true, "订单里一个商品部分退款,退款数量小于商品购买数量,确认收货后,校验生成订单结算单佣金结算单");
		try {

			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(2000);

			// 第一个商品全款退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order, 1);

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;

			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(2000);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);
			/*
			 * ;
			 * 
			 * Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
			 * "验证返回报文");
			 */

			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_006() {
		Logger.start(false, "订单号为空");
		try {
			Logger.comment("前置数据准备结束");
			// orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);
			generateinvoicesCall.callService();

			Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
					"验证返回报文");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_011() {
		Logger.start(true, "有运费订单商品,使用平台券,商家券。确认收货,校验生成下单结算单,佣金结算单 2种结算单");
		try {
			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);
			/*
			 * ;
			 * 
			 * Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
			 * "验证返回报文");
			 */

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_012() {
		Logger.start(true, "有运费订单商品,接单后一个商品部分退款,确认收货后,校验生成订单结算单佣金结算单");
		try {
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(2000);

			// 第一个商品全款退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order, 1);

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;

			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(2000);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);
			/*
			 * ;
			 * 
			 * Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
			 * "验证返回报文");
			 */

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_013() {
		Logger.start(true, "有运费订单商品,接单后一个商品退款加上退部分商品运费,确认收货后,校验生成订单结算单佣金结算单");
		try {
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(2000);

			// 第一个商品全款退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order, 1);

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;

			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(2000);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);
			/*
			 * ;
			 * 
			 * Logger.verifyEquals("ok", generateinvoicesCall.getReturnData(),
			 * "验证返回报文");
			 */

			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_014() {
		Logger.start(true, "有运费订单商品,接单后一个商品退款加退运费超过商品运费,确认收货后,校验生成订单结算单佣金结算单");
		try {
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(2000);

			// 第一个商品全款退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order, 1);

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;

			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(2000);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_015() {
		Logger.start(true, "有运费订单商品,接单后多个商品退款加退运费超过商品运费,确认收货后,校验生成订单结算单佣金结算单");
		try {
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(2000);

			// 第一个商品全款退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order, 1);

			salesrefundsuccessReq.setOrderId(orderId);

			int i = 0;

			for (SalesRefundInfoVo salesRefundInfoVo : applyRefundReq
					.getSalesRefundInfoList()) {

				salesrefundsuccessReq.setRefundBillNo(salesRefundInfoVo
						.getRefundBillNo());
				salesrefundsuccessCall.setData(salesrefundsuccessReq);

				Logger.comment(String.format("orderid: %s 第 %s 个商品 退款执行",
						orderId, i + 1));

				salesrefundsuccessCall.callService();

				Logger.verifyEquals("true",
						salesrefundsuccessCall.getString("success"),
						"验证退货退款成功返回");
				i++;
			}

			Thread.sleep(2000);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_016() {
		Logger.start(true, "校验根据商品二级规格生成的广告费佣金,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder3(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_017() {
		Logger.start(true, "新交易下单,校验生成下单结算单,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder4(true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);

			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_018() {
		Logger.start(true, "新交易下单,确认收货前,有部分退款,校验佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder4(true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);

			// 申请退款
			ApplyRefundReq applyRefundReq = RefundService
					.buildStandApplyRefundReq(placeOrderResp.getOrderList()
							.get(0));

			applyRefundReq.getSalesRefundInfoList().remove(1);
			applyRefundReq.getSalesRefundInfoList().remove(1);

			RefundService.applyRefundCall(applyRefundReq);

			RefundService.approveRefundBillCall(applyRefundReq);

			// // 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(15000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_019() {
		Logger.start(true, "新交易下单,买手为代理买手,有部分退款,校验佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder4(true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			Thread.sleep(3000);

			OrderExtPo record = new OrderWapper()
					.selectOrderExtByOrderId(orderId);

			record.setSellerAgent(true);

			// 更新买手为代理买手 收用费率为固定费率进行计算（千分之6）。
			new OrderWapper().orderExtMapper.updateByPrimaryKey(record);

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GenerateInvoicesOnOrderReceived_020() {
		Logger.start(true, "老交易, 买手为代理买手,校验生成下单结算单,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = SettlementService
					.placeOrder2(true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			long userId = placeOrderResp.getUserId();
			long sellerId = order.getSellerId();

			String updateSql = String
					.format("update ymt_orderext set bSellerAgent=1  where  iorderid=%s",
							orderId);
			// 设置为代理买手
			new DefaultWapper().executeUpdateSql(updateSql);

			// 支付订单
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_021() {
		Logger.start(true, "新交易下单,订单含有平台优惠商品的,校验确认收货,佣金结算 2 种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellerName);
			OrderVo orderVo = TradingCallService.createOrderVo();

			TradingProductVo productVo2 = TradingProductVo.createPro(sellerId,
					sellerName, 5);
			TradingProductVo productVo3 = TradingProductVo.createPro(sellerId,
					sellerName, 5);

			OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
					productVo2.getProductId(), productVo2.getCatalogId());
			OrderItemVo orderItemVo3 = TradingCallService.createOrderItemVo(
					productVo3.getProductId(), productVo3.getCatalogId());

			orderVo.setOrderItems(Lists
					.newArrayList(orderItemVo2, orderItemVo3));

			orderVo.getOrderItems().forEach(
					item -> {

						item.setYmtPromotionAmount(new BigDecimal(new Random()
								.nextInt(10)).add(BigDecimal.ONE));

						item.setFirstCategoryId(SettlementService.firstCataid);
					});

			orderGroupVo.setOrders(Arrays.asList(orderVo));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

			TradingServiceResp placeOrderResp = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			OrderPo orderPo = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = orderPo.getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, useAccountAmount, tradingId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(6000);

			Logger.comment("前置数据准备结束");

			// 查询交易结算表
			List<Map> settlementInvoiceList = new DefaultWapper()
					.selectYmtSettlementInvoice(orderId);

			settlementInvoiceList = settlementInvoiceList.stream()
					.filter(map -> (Integer) map.get("BusinessType") == 1)
					.collect(Collectors.toList());

			if (CollectionUtils.isEmpty(settlementInvoiceList)) {

				Logger.fail(new Exception(String.format(
						"orderId: %s,确认收货结算单 异常,为null", orderId)));

			}

			Map res = settlementInvoiceList.get(0);

			DataUtil.verifyDecimalEquals(orderPo.getYmtPromotionAmount(),
					(BigDecimal) res.get("YmtPromotionAmount"),
					"验证结算的YmtPromotionAmount");

			DataUtil.verifyDecimalEquals(orderPo.getPayableAmount(),
					(BigDecimal) res.get("CashAmount"), "验证结算的TotalAmount");

			DataUtil.verifyDecimalEquals(
					orderPo.getYmtPromotionAmount().add(
							orderPo.getPayableAmount()),
					(BigDecimal) res.get("TotalAmount"), "验证结算的TotalAmount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_022() {
		Logger.start(true, "新交易下单,订单含有平台优惠商品的,校验确认收货前,申请部分退款退货后,确认收货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellerName);
			OrderVo orderVo = TradingCallService.createOrderVo();

			TradingProductVo productVo2 = TradingProductVo.createPro(sellerId,
					sellerName, 5);
			TradingProductVo productVo3 = TradingProductVo.createPro(sellerId,
					sellerName, 5);

			OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
					productVo2.getProductId(), productVo2.getCatalogId());
			OrderItemVo orderItemVo3 = TradingCallService.createOrderItemVo(
					productVo3.getProductId(), productVo3.getCatalogId());

			orderVo.setOrderItems(Lists
					.newArrayList(orderItemVo2, orderItemVo3));

			orderVo.getOrderItems().forEach(
					item -> {

						item.setYmtPromotionAmount(new BigDecimal(new Random()
								.nextInt(10)).add(BigDecimal.ONE));

						item.setFirstCategoryId(SettlementService.firstCataid);
					});

			orderGroupVo.setOrders(Arrays.asList(orderVo));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

			TradingServiceResp placeOrderResp = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			Order order = placeOrderResp.getOrderList().get(0);

			OrderPo orderPo = order.getOrderPo();

			long orderId = orderPo.getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, useAccountAmount, tradingId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);

			// 申请部分退款
			ApplyRefundReq applyRefundReq = RefundService
					.buildStandApplyRefundReq(order);

			BigDecimal refundAmount = BigDecimal.TEN;

			applyRefundReq.getSalesRefundInfoList().remove(1);

			applyRefundReq.getSalesRefundInfoList().get(0)
					.setRefundAmount(refundAmount);

			RefundService.applyRefundCall(applyRefundReq);

			RefundService.approveRefundBillCall(applyRefundReq);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(6000);

			Logger.comment("前置数据准备结束");

			// 查询交易结算表
			List<Map> settlementInvoiceList = new DefaultWapper()
					.selectYmtSettlementInvoice(orderId);

			settlementInvoiceList = settlementInvoiceList.stream()
					.filter(map -> (Integer) map.get("BusinessType") == 1)
					.collect(Collectors.toList());

			// mysql 退款申请表
			RefundBillPo refundBillPo = new OrderShardingWapper()
					.selectRefundBillByOrderId(orderId);

			if (CollectionUtils.isEmpty(settlementInvoiceList)) {

				Logger.fail(new Exception(String.format(
						"orderId: %s,确认收货结算单 异常,为null", orderId)));

			}

			Map res = settlementInvoiceList.get(0);

			DataUtil.verifyDecimalEquals(orderPo.getYmtPromotionAmount()
					.subtract(refundBillPo.getNoSettlementPromotionAmount()),
					(BigDecimal) res.get("YmtPromotionAmount"),
					"验证结算的YmtPromotionAmount");

			DataUtil.verifyDecimalEquals(
					orderPo.getPayableAmount().subtract(refundAmount),
					(BigDecimal) res.get("CashAmount"), "验证结算的TotalAmount");

			DataUtil.verifyDecimalEquals(((BigDecimal) res.get("CashAmount"))
					.add(((BigDecimal) res.get("YmtPromotionAmount"))),
					(BigDecimal) res.get("TotalAmount"), "验证结算的TotalAmount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings("rawtypes")
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_023() {
		Logger.start(true, "新交易下单,订单含有平台优惠商品的,校验确认收货后,申请退款退货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellerName);
			OrderVo orderVo = TradingCallService.createOrderVo();

			TradingProductVo productVo2 = TradingProductVo.createPro(sellerId,
					sellerName, 5);
			TradingProductVo productVo3 = TradingProductVo.createPro(sellerId,
					sellerName, 5);

			OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
					productVo2.getProductId(), productVo2.getCatalogId());
			OrderItemVo orderItemVo3 = TradingCallService.createOrderItemVo(
					productVo3.getProductId(), productVo3.getCatalogId());

			orderVo.setOrderItems(Lists
					.newArrayList(orderItemVo2, orderItemVo3));

			orderVo.getOrderItems().forEach(
					item -> {

						item.setYmtPromotionAmount(new BigDecimal(new Random()
								.nextInt(10)).add(BigDecimal.ONE));

						item.setFirstCategoryId(SettlementService.firstCataid);
					});

			orderGroupVo.setOrders(Arrays.asList(orderVo));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

			TradingServiceResp placeOrderResp = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			Order order = placeOrderResp.getOrderList().get(0);

			OrderPo orderPo = order.getOrderPo();

			long orderId = orderPo.getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, useAccountAmount, tradingId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(6000);

			// 申请部分退款
			ApplyRefundReq applyRefundReq = RefundService.applyRefund(order);

			applyRefundReq
					.getSalesRefundInfoList()
					.get(0)
					.setRefundAmount(
							applyRefundReq.getSalesRefundInfoList().get(0)
									.getRefundAmount().subtract(BigDecimal.TEN));

			RefundService.approveRefundBillCall(applyRefundReq);

			Logger.comment("前置数据准备结束");

			// 查询交易结算表
			List<Map> settlementInvoiceList = new DefaultWapper()
					.selectYmtSettlementInvoice(orderId);

			settlementInvoiceList = settlementInvoiceList.stream()
					.filter(map -> (Integer) map.get("BusinessType") == 1)
					.collect(Collectors.toList());

			if (CollectionUtils.isEmpty(settlementInvoiceList)) {

				Logger.fail(new Exception(String.format(
						"orderId: %s,确认收货结算单 异常,为null", orderId)));

			}

			Map res = settlementInvoiceList.get(0);

			DataUtil.verifyDecimalEquals(orderPo.getYmtPromotionAmount(),
					(BigDecimal) res.get("YmtPromotionAmount"),
					"验证结算的YmtPromotionAmount");

			DataUtil.verifyDecimalEquals(orderPo.getPayableAmount(),
					(BigDecimal) res.get("CashAmount"), "验证结算的TotalAmount");

			DataUtil.verifyDecimalEquals(
					orderPo.getYmtPromotionAmount().add(
							orderPo.getPayableAmount()),
					(BigDecimal) res.get("TotalAmount"), "验证结算的TotalAmount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_024() {
		Logger.start(true, "正常购买一份安利会普通商品,已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.ZERO, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			// 生成安利结算
			generateAnliSettlementReq.setOrderId(orderId);

			generateAnliSettlementCall.setData(generateAnliSettlementReq);
			generateAnliSettlementCall.callService();

			// 执行买手结算
			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			generateinvoicesCall.callService();

			Thread.sleep(6000);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_025() {
		Logger.start(true, "正常购买一份普通商品,两个商品均设置了返点比率，已结算，验证结算数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;

			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();
			long sellerId = placeOrder.getOrderList().get(0).getSellerId();
			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(10000);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国际段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			// 拼邮国内段发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);
			TradingSyncService.getSyncResult(orderId);

			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);
			TradingSyncService.getSyncResult(orderId);

			Logger.comment("前置数据准备结束");

			// 生成安利结算
			generateAnliSettlementReq.setOrderId(orderId);

			generateAnliSettlementCall.setData(generateAnliSettlementReq);
			generateAnliSettlementCall.callService();

			// 执行买手结算
			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			generateinvoicesCall.callService();

			Thread.sleep(6000);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_026() {
		Logger.start(true, "正常购买一份安利会普通商品,确认收货前，商品依次全部退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			// 生成安利结算
			generateAnliSettlementReq.setOrderId(orderId);

			generateAnliSettlementCall.setData(generateAnliSettlementReq);
			generateAnliSettlementCall.callService();

			Thread.sleep(6000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			orderSettlementReq.setOrderId(orderId);
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_027() {
		Logger.start(true, "正常购买一份普通商品,确认收货前，商品部分退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			// 生成安利结算
			generateAnliSettlementReq.setOrderId(orderId);

			generateAnliSettlementCall.setData(generateAnliSettlementReq);
			generateAnliSettlementCall.callService();

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			orderSettlementReq.setOrderId(orderId);
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_028() {
		Logger.start(true, "正常购买一份安利会普通商品,确认收货后，商品依次全部退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			// 生成安利结算
			generateAnliSettlementReq.setOrderId(orderId);

			generateAnliSettlementCall.setData(generateAnliSettlementReq);
			generateAnliSettlementCall.callService();

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 0);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			orderSettlementReq.setOrderId(orderId);
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_029() {
		Logger.start(true, "正常购买一份安利会普通商品,确认收货前，商品部分退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			long memberId = 2002;
			int memberOrderType = 0;
			TradingServiceResp placeOrder = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, memberId,
							memberOrderType);
			Long userId = placeOrder.getUserId();

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();

			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");

			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);

			// 生成安利结算
			generateAnliSettlementReq.setOrderId(orderId);

			generateAnliSettlementCall.setData(generateAnliSettlementReq);
			generateAnliSettlementCall.callService();

			Thread.sleep(10000);

			AnlihuiCallService.anliOrderRefund(
					placeOrder.getOrderList().get(0), true, 1);

			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());

			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			TradingSyncService.getSyncResult(orderId);

			orderSettlementReq.setOrderId(orderId);
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_030() {
		Logger.start(true, "新交易下单,满减包邮，校验生成下单结算单,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithFullReductionFreeFreight(true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(6000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_031() {
		Logger.start(true, "新交易下单,买家承担鉴别费和鉴别运费，校验生成下单结算单,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(
							AuthenticateFreightTypeEnum.BUYER, BigDecimal.ONE,
							AuthenticateFeeTypeEnum.BUYER, BigDecimal.TEN);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);

			// 商家发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 3, true);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GenerateInvoicesOnOrderReceived_032() {
		Logger.start(true, "新交易下单,买手承担鉴别费和鉴别运费，校验生成下单结算单,佣金结算单 2种结算单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(
							AuthenticateFreightTypeEnum.SELLER, BigDecimal.ONE,
							AuthenticateFeeTypeEnum.SELLER, BigDecimal.TEN);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);

			// 商家发货
			TradingCallService.delivery(sellerId, orderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 3, true);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(10000);

			Logger.comment("前置数据准备结束");

			orderSettlementReq.setOrderId(orderId);
			generateinvoicesCall.setData(orderSettlementReq);

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	public static void main(String[] args) {

		Ts_GenerateInvoicesOnOrderReceived test = new Ts_GenerateInvoicesOnOrderReceived();

		test.verifyDb();
	}
}
